package com.link.base.base.esb.model;

import java.util.HashMap;
import java.util.Map;

/**
 * ESB返回信息
 *
 * @author: liuqixin
 * @date: 2020/08/19 14:17
 */
public class EsbInfo {

    /**
     * 标记数据来源 - ESB
     */
    public static final String SOURCE_ESB = "ESB";

    /**
     * returnStatus 返回值，标识成功
     */
    public static final String RT_STATUS_SUCCESS = "S";

    /**
     * returnStatus 返回值，标识警告
     */
    public static final String RT_STATUS_WARN = "W";

    /**
     * returnStatus 返回值，标识错误
     */
    public static final String RT_STATUS_ERROR = "E";

    /**
     * 这里主要是接受ESB数据时的返回参数定义
     * 返回的returnCode和returnMsg的对应，根据returnCode获取对应的Msg
     */
    public static final Map<String, String> esbCodeMsgMap = new HashMap<>();

    /**
     * 错误编码定定义
     */
    public static final String E0999 = "E0999-CRM";
    public static final String E0001 = "E0001-CRM";
    public static final String E0002 = "E0002-CRM";
    public static final String E0003 = "E0003-CRM";
    public static final String E0004 = "E0004-CRM";
    public static final String E0005 = "E0005-CRM";
    public static final String E0006 = "E0006-CRM";
    public static final String E0007 = "E0007-CRM";
    public static final String E0008 = "E0008-CRM";
    public static final String E0009 = "E0009-CRM";

    /**
     * 提示信息定义
     */
    public static final String W0001 = "W0001-CRM";
    public static final String W0002 = "W0002-CRM";
    public static final String W0003 = "W0003-CRM";
    public static final String W0004 = "W0004-CRM";

    /**
     * 成功编码定义
     */
    public static final String A0001 = "A0001-CRM";
    public static final String A0002 = "A0002-CRM";

    /**
     * map初始化
     */
    static {
        // E 类型错误定义
        // E0999-CRM：未知错误，详见Attr1
        esbCodeMsgMap.put(E0999, "未知错误，详见Attr1");
        esbCodeMsgMap.put(E0001, "EsbInfo对象为空");
        esbCodeMsgMap.put(E0002, "保存数据对象为空");
        esbCodeMsgMap.put(E0003, "时间格式错误");
        esbCodeMsgMap.put(E0004, "查询原数据异常");
        esbCodeMsgMap.put(E0005, "创建数据库记录异常");
        esbCodeMsgMap.put(E0006, "更新数据库记录异常");
        esbCodeMsgMap.put(E0007, "字段非空校验失败");

        // A 类型信息定义
        esbCodeMsgMap.put(A0001, "创建数据库记录成功");
        esbCodeMsgMap.put(A0002, "更新数据库记录成功");

        // W 类型信息定义
        esbCodeMsgMap.put(W0001, "已成功保存，但未能查询到父组织或职位信息");
        esbCodeMsgMap.put(W0002, "已成功保存，但未能关联到组织或职位信息");
        esbCodeMsgMap.put(W0003, "已成功保存，但未能赋值员工组织信息");
        esbCodeMsgMap.put(W0004, "已成功保存，但未能赋值员工职位信息");

    }

    /**
     * 根据返回编码获取返回信息
     *
     * @param returnCode
     * @return
     */
    public static String getEsbCodeMagMap(String returnCode) {
        return esbCodeMsgMap.get(returnCode);
    }


    /**
     * 该字段为接 口调用的流水号，每次该字段为接 口调用的流水号，每次调用接口时都会有一个 instId产生
     * 提供方开发接口时要包含这个字段，类型 提供方开发接口时要包含这个字段，类型为 String 长度为50 +
     */
    private String instId;
    /**
     * 调用方调用接口的系统时间，格式为：yyyy-MM-dd HH24:mm:ss.SSS
     */
    private String requestTime;
    /**
     * 响应时间，格式为：yyyy-MM-dd HH24:mm:ss.SSS
     */
    private String responseTime;

    /**
     * 接口返回状态，该字段值为S或W或E
     * S：表示接口调用成功，包括技术上的成功（没有报错）和业务上的成功（单据处理正常）
     * W：表示接口警告，包括技术上的警告（如处理时间超长）和业务上的警告（如查询接口未查询到数据）
     * E：表示接口报错，包括技术上的报错（如验证失败、字段类型不匹配等）和业务上的报错（如单据处理失败，单据号不能匹配）
     */
    private String returnStatus;

    /**
     * 接口返回状态码，与returnMsg成对出现
     * 由业务系统自行设定
     */
    private String returnCode;

    /**
     * 返回信息
     */
    private String returnMsg;

    private String attr1;

    private String attr2;

    private String attr3;

    public static String getRtStatusSuccess() {
        return RT_STATUS_SUCCESS;
    }

    public static String getRtStatusWarn() {
        return RT_STATUS_WARN;
    }

    public static String getRtStatusError() {
        return RT_STATUS_ERROR;
    }

    public static Map<String, String> getEsbCodeMsgMap() {
        return esbCodeMsgMap;
    }

    public String getInstId() {
        return instId;
    }

    public EsbInfo setInstId(String instId) {
        this.instId = instId;
        return this;
    }

    public String getRequestTime() {
        return requestTime;
    }

    public EsbInfo setRequestTime(String requestTime) {
        this.requestTime = requestTime;
        return this;
    }

    public String getResponseTime() {
        return responseTime;
    }

    public EsbInfo setResponseTime(String responseTime) {
        this.responseTime = responseTime;
        return this;
    }

    public String getReturnStatus() {
        return returnStatus;
    }

    public EsbInfo setReturnStatus(String returnStatus) {
        this.returnStatus = returnStatus;
        return this;
    }

    public String getReturnCode() {
        return returnCode;
    }


    public EsbInfo setReturnCode(String returnCode) {
        this.returnCode = returnCode;
        return this;
    }

    /**
     * 设置返回编码时，同时设置返回信息
     *
     * @param returnCode
     */
    public EsbInfo setReturnCodeMsg(String returnCode) {
        setReturnCode(returnCode);
        this.returnMsg = esbCodeMsgMap.get(returnCode);
        return this;
    }

    public String getReturnMsg() {
        return returnMsg;
    }

    public EsbInfo setReturnMsg(String returnMsg) {
        this.returnMsg = returnMsg;
        return this;
    }

    public String getAttr1() {
        return attr1;
    }

    public EsbInfo setAttr1(String attr1) {
        this.attr1 = attr1;
        return this;
    }

    public String getAttr2() {
        return attr2;
    }

    public EsbInfo setAttr2(String attr2) {
        this.attr2 = attr2;
        return this;
    }

    public String getAttr3() {
        return attr3;
    }

    public EsbInfo setAttr3(String attr3) {
        this.attr3 = attr3;
        return this;
    }

    @Override
    public String toString() {
        return "EsbInfo{"
                + "instId='"
                + instId + '\''
                + ", requestTime='" + requestTime + '\''
                + ", responseTime='" + responseTime + '\''
                + ", returnStatus='" + returnStatus + '\''
                + ", returnCode='" + returnCode + '\''
                + ", returnMsg='" + returnMsg + '\''
                + ", attr1='" + attr1 + '\''
                + ", attr2='" + attr2 + '\''
                + ", attr3='" + attr3 + '\'' + '}';
    }

}
